package com.mcms.service.fz;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.mcms.service.common.DealResult;
import com.mcms.util.DBHelper;
import com.mcms.util.MapUtil;
import com.mcms.web.vo.DWZResult;
import com.mcms.web.vo.DictCache;

/**
 * 判断是否已经分诊
 * 1.已经分诊：获取接诊医生的ID和其部门ID
 * 2.未分诊：不进行查询
 * @author 
 */
public class IsHaveFZInfoService {

	public static Map execute(Map sessionMap, Map paramMap) {

		Map fzDoctorInfo = new HashMap();
		
		IsHaveFZInfoService fZInfoService = new IsHaveFZInfoService();
		
		// 根据客户号和就诊号查询该记录是否已存在
		fzDoctorInfo = fZInfoService.isHaveFZInfo(sessionMap, paramMap);
			
		return fzDoctorInfo;
	}
	
	/**
	 * 判断当前此客户是否有分诊记录，有：true，否：false
	 * 
	 * @return
	 */
	private Map isHaveFZInfo(Map sessionMap, Map paramMap){
		String doctorId = (String)paramMap.get("doctorid");// 客户预约就诊号
		String customId = (String)paramMap.get("customid");// 客户号ID
		Map resultMap = new HashMap();
		
		String sql = "select t1.deal_doctor,t1.remark from MCMS_CUSTOM_DOCTOR_RALATION t1, MCMS_CUSTOM_DOCTOR t2 " +
				"where t1.custom_id = t2.custom_id and t1.doctor_id = t2.doctor_id and deal_time is not null";
		DBHelper dbh = DBHelper.getInstance();
		List list = dbh.query(sql);// 查询分诊后分配给了哪位医生（ID）
		
		String dealDoctor = null;
		String remark = null;
		Integer deptId = null; 
		if(list.size()>0){
			Map<String, String> map = (Map<String, String>) list.get(0);
			
			dealDoctor = map.get("deal_doctor");
			resultMap.put("dealDoctor", Integer.parseInt(dealDoctor));
			remark = map.get("remark");
			resultMap.put("remark",remark);
			 
			String sqlInner = "select departmentid from view_mcms_user_info where id="+dealDoctor.trim();
			List listResult = dbh.query(sqlInner);
			if(listResult.size()>0){
				Map deptMap = (Map)listResult.get(0);
				deptId = MapUtil.getInteger(deptMap, "departmentid");
				resultMap.put("deptId", deptId);
			}
		}
		
		return resultMap;
	}
}
